package jdbc3_25.homework;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class JDBCDemo06 {
    public static void main(String[] args) {
        try(Connection connection = DBUtil01.getConnection();){
            Statement statement = connection.createStatement();
            String sql = "SELECT t.name,t.salary,c.name,c.floor " +
                    "FROM teacher t " +
                    "JOIN class c ON t.id=c.teacher_id " +
                    "WHERE t.name='王克晶' ";

            ResultSet rs = statement.executeQuery(sql);
            while (rs.next()){
                String tName = rs.getString("t.name");
                int tSalary = rs.getInt("t.salary");
                String cName = rs.getString("c.name");
                int cFloor = rs.getInt("c.floor");
                String line = String.join(",", tName, tSalary + "", cName, cFloor + "");
                System.out.println(line);

            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
